home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kpixmap.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  7.1 KB  |  214 lines

  1. /*
  2.  *  This file is part of the KDE libraries
  3.  *  Copyright (C) 1998    Mark Donohoe <donohoe@kde.org>
  4.  *             Stephan Kulow <coolo@kde.org>
  5.  *
  6.  *  $Id: kpixmap.h 465272 2005-09-29 09:47:40Z mueller $
  7.  *
  8.  *  This library is free software; you can redistribute it and/or
  9.  *  modify it under the terms of the GNU Library General Public
  10.  *  License as published by the Free Software Foundation; either
  11.  *  version 2 of the License, or (at your option) any later version.
  12.  *
  13.  *  This library is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  *  Library General Public License for more details.
  17.  *
  18.  *  You should have received a copy of the GNU Library General Public License
  19.  *  along with this library; see the file COPYING.LIB.  If not, write to
  20.  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21.  *  Boston, MA 02110-1301, USA.
  22.  */
  23.  
  24. #ifndef __KPIXMAP_H__
  25. #define __KPIXMAP_H__
  26.  
  27. #include <qpixmap.h>
  28.  
  29. #include <kdelibs_export.h>
  30.  
  31. const int KColorMode_Mask    = 0x00000300;
  32. const int WebOnly     = 0x00000200;
  33. const int LowOnly    = 0x00000300;
  34.  
  35. class KPixmapPrivate;
  36.  
  37. /**
  38.  * Off-screen paint device with extended features.
  39.  
  40.  * KPixmap has two new color modes, WebColor and LowColor, applicable
  41.  * to 8bpp displays.
  42.  
  43.  * In WebColor mode all images are dithered to the Netscape palette,
  44.  * even when they have their own color table. WebColor is the default
  45.  * mode for KPixmap so that standard applications can share the Netscape
  46.  * palette across the desktop.
  47.  
  48.  * In LowColor mode images are checked to see if their color table
  49.  * matches the KDE icon palette. If the color tables do not match, the
  50.  * images are dithered to a minimal 3x3x3 color cube. LowColor mode can
  51.  * be used to load icons, background images etc. so that components of
  52.  * the desktop which are always present use no more than 40 colors.
  53.  
  54.  * @author Mark Donohoe (donohoe@kde.org)
  55.  * @version $Id: kpixmap.h 465272 2005-09-29 09:47:40Z mueller $
  56.  */
  57. class KDEFX_EXPORT KPixmap : public QPixmap
  58. {
  59. public:
  60.     /**
  61.      * This enumeration provides a color pallete specification
  62.      * @see KPixmap::convertFromImage(), KPixmap::load()
  63.      */
  64.         enum ColorMode { Auto,   //!< Convert to monochrome if possible
  65.              Color,  //!< Native display depth
  66.              Mono,   //!< Monochrome pixmap
  67.              LowColor, //!< 3x3x3 color cube (or monochrome)
  68.              WebColor //!< Netscape pallete (or monochrome)
  69.     };
  70.     /**
  71.      * This enumeration provides a gradient mode specification
  72.      */
  73.         enum GradientMode { Horizontal,
  74.                 Vertical,
  75.                 Diagonal,
  76.                 CrossDiagonal
  77.     };
  78.  
  79.     /**
  80.      * Constructs a null pixmap.
  81.      */
  82.          KPixmap() : QPixmap() {};
  83.  
  84.     /**
  85.      * Destructs the pixmap.
  86.          * ### KDE 4: remove
  87.      */
  88.     ~KPixmap();
  89.  
  90.     /**
  91.      * Copies the QPixmap @p pix.
  92.          */
  93.     KPixmap(const QPixmap& pix);
  94.  
  95.     /**
  96.      * Converts an image and sets this pixmap.
  97.      *
  98.      * The conversion_flags argument is a bitwise-OR from the
  99.      * following choices. The options marked (default) are the
  100.      * choice if no other choice from the list is included (they
  101.      * are zero):
  102.      *
  103.      * Color/Mono preference
  104.      *
  105.      * @li WebColor -  If the image has depth 1 and contains
  106.      * only black and white pixels then the pixmap becomes monochrome. If
  107.      * the pixmap has a depth of 8 bits per pixel then the Netscape
  108.      * palette is used for the pixmap color table.
  109.      * @li LowColor - If the image has depth 1 and contains only black and
  110.      * white pixels then the pixmap becomes monochrome. If the pixmap has a
  111.      * depth of 8 bits per pixel and the image does not posess a color table
  112.      * that matches the Icon palette a 3x3x3 color cube is used for the
  113.      * pixmap color table.
  114.      * @li AutoColor (default) - If the image has depth 1 and contains
  115.      * only black and white pixels, then the pixmap becomes
  116.      * monochrome.
  117.      * @li ColorOnly - The pixmap is dithered/converted to the native
  118.      * display depth.
  119.      * @li MonoOnly - The pixmap becomes monochrome. If necessary, it
  120.      * is dithered using the chosen dithering algorithm.
  121.      *
  122.      * Dithering mode preference, for RGB channels
  123.      *
  124.      * @li DiffuseDither (default) - A high quality dither.
  125.      * @li OrderedDither - A faster more ordered dither.
  126.      * @li ThresholdDither - No dithering, closest color is used.
  127.      *
  128.      * Dithering mode preference, for alpha channel
  129.      *
  130.      * @li DiffuseAlphaDither - A high quality dither.
  131.      * @li OrderedAlphaDither - A faster more ordered dither.
  132.      * @li ThresholdAlphaDither (default) - No dithering.
  133.      *
  134.      * Color matching versus dithering preference
  135.      *
  136.      * @li PreferDither - Always dither 32-bit images when the image
  137.      * is being converted to 8-bits. This is the default when
  138.      * converting to a pixmap.
  139.      * @li AvoidDither - Only dither 32-bit images if the image has
  140.      * more than 256 colors and it is being converted to 8-bits.
  141.      * This is the default when an image is converted for the
  142.      * purpose of saving to a file.
  143.      *
  144.      * Passing 0 for @p conversion_flags gives all the default
  145.      * options.
  146.      *
  147.      * @param img the image to convert
  148.      * @param conversion_flags bitmask, described above
  149.      * @return @p true if successful.
  150.      **/
  151.     bool convertFromImage( const QImage &img, int conversion_flags );
  152.  
  153.     /**
  154.      * This is an overloaded member function, provided for
  155.      * convenience. It differs from the above function only in
  156.      * what argument(s) it accepts.
  157.      * @param img the image to convert
  158.      * @param mode a ColorMode to apply
  159.      * @return @p true if successful.
  160.      **/
  161.     bool convertFromImage( const QImage &img, ColorMode mode = WebColor );
  162.  
  163.     /**
  164.      * Loads a pixmap from the file @p fileName.
  165.      *
  166.      * If format is specified, the loader attempts to read the
  167.      * pixmap using the specified format. If format is not
  168.      * specified (default), the loader reads a few bytes from the
  169.      * header to guess the file format.
  170.      *
  171.      * The QImageIO documentation lists the supported image
  172.      * formats and explains how to add extra formats.
  173.      *
  174.      * @param fileName the name of the file to load the image from
  175.      * @param format the format for the image
  176.      * @param conversion_flags a bitmask, as described in 
  177.      *        convertFromImage()
  178.      * @return @p true if successful, or false if the pixmap
  179.      *         could not be loaded.
  180.      **/
  181.     bool load( const QString& fileName, const char *format,
  182.         int conversion_flags );
  183.  
  184.     /**
  185.      * This is an overloaded member function, provided for
  186.      * convenience. It differs from the above function only in
  187.      * what argument(s) it accepts.
  188.      * @param fileName the name of the file to load the image from
  189.      * @param format the format for the image
  190.      * @param mode a ColorMode to apply
  191.      * @return @p true if successful, or false if the pixmap
  192.      *         could not be loaded.
  193.      **/
  194.     bool load( const QString& fileName,
  195.         const char *format = 0,
  196.         ColorMode mode = WebColor );
  197.  
  198.     /**
  199.      * Returns true if the image posesses a color table that
  200.      * matches the Icon palette or false otherwise.
  201.      *
  202.      * An image with one color not found in the Icon palette is
  203.      * considered to be a match, since this extra color may be a
  204.      * transparent background.
  205.      * @param image the image to test
  206.      **/
  207.     bool checkColorTable(const QImage &image);
  208.  
  209. private:
  210.     KPixmapPrivate *d;
  211. };
  212.  
  213. #endif
  214.